<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">支付</block>
		</cu-custom>
		<div class="container">
			<div class="total">
				<div class="label">订单号</div>
				<div class="txt">{{orderId}}</div>
			</div>
			<div class="total">
				<div class="label">订单金额</div>
				<div class="txt">¥ {{actualPrice}}</div>
			</div>
			<div class="pay-list">
				<div class="h">请选择支付方式</div>
				<div class="b">
					<!--  #ifdef  MP-WEIXIN -->
					<div class="item" @tap="paytype='wxpaywxapp'" v-if="small_is_use == 'on'">
						<div class="checkbox" :class="['wxpaywxapp'===paytype ?'checked':'']"></div>
						<div class="icon-wechat"></div>
						<div class="name">微信支付</div>
					</div>
					<!--  #endif -->

					<!--  #ifdef  MP-ALIPAY -->
					<div class="item" @tap="paytype='malipaymyapp'" v-if="zhifu_is_use == 'on'">
						<div class="checkbox" :class="['malipaymyapp'===paytype ?'checked':'']"></div>
						<div class="icon-Alipay"></div>
						<div class="name">支付宝</div>
					</div>
					<!--  #endif -->

					<!--  #ifdef  H5-->
					<div class="item" @tap="paytype='wxpayh5'" v-if="hfive_is_use == 'on'">
						<div class="checkbox" :class="['wxpayh5'===paytype ?'checked':'']"></div>
						<div class="icon-wechat"></div>
						<div class="name">微信支付</div>
					</div>
					<div class="item" @tap="paytype='malipaynew'" v-if="zhifu_is_use=='on'">
						<div class="checkbox" :class="['malipaynew'===paytype ?'checked':'']"></div>
						<div class="icon-Alipay"></div>
						<div class="name">支付宝</div>
					</div>
					<!--  #endif -->
					<!--  #ifdef  APP-PLUS -->
					<div class="item" @tap="paytype='wxpayappplus'" v-if="app_is_use=='on'">
						<div class="checkbox" :class="['wxpayappplus'===paytype ?'checked':'']"></div>
						<div class="icon-wechat"></div>
						<div class="name">微信支付</div>
					</div>
					<div class="item" @tap="paytype='malipayappplus'" v-if="zhifu_is_use=='on'">
						<div class="checkbox" :class="['malipayappplus'===paytype ?'checked':'']"></div>
						<div class="icon-Alipay"></div>
						<div class="name">支付宝</div>
					</div>
					<!--  #endif -->
					<div class="item" @tap="paytype='deposit'">
						<div class="checkbox" :class="['deposit'===paytype ?'checked':'']"></div>
						<div class="icon-balance"></div>
						<div class="name">预存款支付 (余额：{{advance}})</div>
					</div>
					<div class="item" @tap="showCredit()">
						<div class="checkbox" :class="['credit'===paytype ?'checked':'']"></div>
						<div class="icon-credit"></div>
						<div class="name">クレジットカード</div>
					</div>
					<div class="item" @tap="showJcbPremo()">
						<div class="checkbox" :class="['jcbpremo'===paytype ?'checked':'']"></div>
						<div class="icon-credit"></div>
						<div class="name">JCB PREMO</div>
					</div>
					<view class="payment_credit" v-if="paytype=='credit'">
						<div class="block-form indent" id="shopping_order_payment" style="">
							<div class="block-form__item">
								<label class="">卡号<span class="required">※</span></label>
								<div>
									<input type="text" id="shopping_order_card_no" name="card_no" pattern="\d*" maxlength="19" class="card-number size-4" v-model="cardNo"
									 placeholder="输入半角数字">
								</div>
							</div>
							<div class="block-form__item">
								<label class="">有效期限<span class="required">※</span></label>
								<div>
									<select id="shopping_order_expire_month" v-model="expire_month" class="size-4em mb-0">
										<option value="01">01</option>
										<option value="02">02</option>
										<option value="03">03</option>
										<option value="04">04</option>
										<option value="05">05</option>
										<option value="06">06</option>
										<option value="07">07</option>
										<option value="08">08</option>
										<option value="09">09</option>
										<option value="10">10</option>
										<option value="11">11</option>
										<option value="12">12</option>
									</select>
									<span>月 / 20</span>
									<select id="shopping_order_expire_year" v-model="expire_year" class="size-4em mb-0">
										<option value="20">20</option>
										<option value="21">21</option>
										<option value="22">22</option>
										<option value="23">23</option>
										<option value="24">24</option>
										<option value="25">25</option>
										<option value="26">26</option>
										<option value="27">27</option>
										<option value="28">28</option>
										<option value="29">29</option>
										<option value="30">30</option>
										<option value="31">31</option>
										<option value="32">32</option>
										<option value="33">33</option>
										<option value="34">34</option>
										<option value="35">35</option>
									</select>
									<span>年</span>
								</div>
							</div>
							<div class="block-form__item">
								<label class="">名义人<span class="required">※</span></label>
								<div>
									<input type="text" id="shopping_order_card_name1" name="_shopping_order_card_name1" v-model="card_name1"
									 maxlength="25" class="size-4" placeholder="（名） TARO">
									<input type="text" id="shopping_order_card_name2" name="_shopping_order_card_name2" v-model="card_name2"
									 maxlength="24" class="size-4" placeholder="（姓） YAMADA">
								</div>
							</div>
							<div class="block-form__item">
								<label>安全码<span class="required">※</span></label>
								<div>
									<input type="text" id="shopping_order_security_code" name="_shopping_order_security_code" v-model="security_code"
									 maxlength="3" class="size-4" placeholder="123">
								</div>
							</div>
							<div class="block-form__item">
								<label>支付方式</label>
								<div>
									<select id="shopping_order_credit_pay_methods" name="_shopping_order[credit_pay_methods]" class="size-2">
										<option value="1-0">一次付清</option>
									</select>
								</div>
							</div>
						</div>
					</view>
					<view class="payment_credit" v-if="paytype=='jcbpremo'">
						<div class="block-form indent" id="shopping_order_jcb_payment" style="">
							<div class="block-form__item">
								<label class="">カード番号<span class="required">※</span></label>
								<div>
									<input type="text" id="shopping_jcbcard_no" autocomplete="off" name="jcbcard_no" maxlength="19" pattern="\d*" class="card-number size-4" v-model="jcbCardNo"
									 placeholder="半角数字で入力">
								</div>
							</div>
							
							<div class="block-form__item">
								<label class="">認証番号<span class="required">※</span></label>
								<div>
									<input type="password" id="shopping_order_jcb_password" autocomplete="off" name="jcbPassword" v-model="jcbPassword"
									 maxlength="25" class="size-4" placeholder="123456">
								</div>
							</div>
						</div>
					</view>
				</div>
			</div>

			<!--  #ifdef  MP-WEIXIN -->
			<div class="tips">微信小程序只支持微信支付，如需其它支付方式，请在网页版支付</div>
			<!--  #endif -->
			<!--  #ifdef  MP-ALIPAY -->
			<div class="tips">支付宝小程序只支持支付宝支付，如需其它支付方式，请在网页版支付</div>
			<!--  #endif -->

			<div class="pay-btn" @click="startPay">确定</div>
		</div>
	</view>
</template>
<script>
	import {
		payDetailApi,
		getPaymentListApi,
		doPaymentCreditApi,
		doPaymentJcbPreMoApi,
		doPaymentBalanceApi,
		payDopaymentApi,
		doPaymentMpH5Api,
		memberInfoApi,
		doPaymentAliAppAPi,
		doPaymentWxAppAPi,
		loginWechatApi,
		wechatPayApi,
		payCardApi,
		getPaymentIsUseApi
	} from "../../server/config.js";
	import {
		toLogin
	} from "@/server/api.js";

	//import Cleave from 'node_modules/cleave.js/dist/cleave-esm.min.js';

	export default {
		onLoad(opt) {
			this.orderId = opt.orderId;
			this.code = opt.code;
			this.orderDetail();
			this.addScript('https://p01.mul-pay.jp/ext/js/token.js');
		},

		onShow() {
			//判断是否登录，没有直接跳转登录界面
			toLogin();
			uni.getStorageSync("bonusName", ""); // 清除红包信息
			uni.getStorageSync("bonus_id", "");
			this.advance = uni.getStorageSync("advance");
			// #ifdef H5
			this.iswechatH5 = this.is_weixn();
			// #endif

			if (this.code) {
				this.wxpayh5Pay();
			}

			// #ifdef MP-WEIXIN
			if (!uni.getStorageSync("openId")) {
				this.getWechatOpenid();
			}
			// #endif
		},
		mounted() {
			this.getPayment();
			this.GetAdvance();
			this.getPaymentIsUse();
		},
		data() {
			return {
				orderId: 0,
				actualPrice: 0.0,
				advance: "",
				payParams: [],
				balance_amount: 0.0,
				pay_id: "",
				//默认支付方式显示
				// #ifdef MP-WEIXIN
				paytype: "wxpaywxapp", //支付类型
				// #endif
				// #ifdef MP-ALIPAY
				paytype: "malipaymyapp", //支付类型
				// #endif
				// #ifdef H5
				paytype: "wxpayh5", //支付类型
				// #endif
				// #ifdef APP-PLUS
				paytype: "wxpayappplus", //支付类型
				paytype: "bankcard", //支付类型
				// #endif
				alipaywap: "", // 支付宝手机网页支付地址
				goods_name: "", // 订单商品名称 即支付订单显示描述 取订单第一个商品的名字
				advance: 0, // 余额  取缓存
				code: "", // 微信code
				small_is_use: "", //微信支付、小程序
				hfive_is_use: "", //微信支付、h5
				app_is_use: "", //微信支付、app
				zhifu_is_use: "", //支付宝支付
				iswechatH5: "", //是否是微信H5支付
				cardNo: "", //信用卡番号
				expire_month: "01", //过期月
				expire_year: "20", //过期年,
				card_name1: "", //名义人
				card_name2: "", //名义人
				security_code: "", //安全码
				jcbCardNo: "", //JCB 卡号
				jcbPassword: ""　// JCB 认证番号
			};
		},
		methods: {

			showCredit() {
				this.paytype = 'credit'

				//クレジットカード
				this.$nextTick(() => {
					new Cleave('#shopping_order_card_no .uni-input-input', {
						creditCard: true
					});
				})
			},
			
			showJcbPremo(){
				this.paytype = 'jcbpremo';
				
				//クレジットカード
				this.$nextTick(() => {
					new Cleave('#shopping_jcbcard_no .uni-input-input', {
						creditCard: true
					});
				})
			},

			addScript(url) {
				var new_element = document.getElementById("gmotoken");
				if(!new_element){
					new_element = document.createElement("script");
					new_element.setAttribute("type", "text/javascript");
					new_element.setAttribute("id","gmotoken")
					new_element.setAttribute("src", url);
					document.body.appendChild(new_element);
				}
			},
			// #ifdef H5
			is_weixn() {
				var ua = navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == "micromessenger") {
					return true;
				} else {
					return false;
				}
			},
			// #endif

			async orderDetail() {
				const data = await payDetailApi({
					order_id: this.orderId
				});
				if (data.data.pay_detail === false) {
					uni.showToast({
						title: "不存在此订单",
						icon: "none",
						duration: 2000
					});
					uni.navigateTo({
						url: "/pages/index/main"
					});

					return false;
				}
				this.actualPrice = data.data.info.total_fee;
				this.order = data.data.info;
				this.order_id = this.$root.$mp.query.orderId;
				this.payment_list = data.data.info.payment_list;
				this.alipaywap = data.data.other.url;
				this.goods_name = data.data.other.goods_name;

				console.log('-----')
				console.log(data)
				console.log('-----')
			},

			selectPayment(paymentId) {
				this.pay_id = paymentId;
			},
			async GetAdvance() {
				const data = await memberInfoApi({});
				this.advance = data.data.info.user_money;
			},
			async doPay() {
				if (this.pay_id === "balance") {
					let data = await doPaymentBalanceApi({
						order_id: this.$root.$mp.query.orderId,
						pay_id: this.pay_id
					});
					if (!data.data.dopay) {
						uni.showToast({
							title: data.data.info,
							icon: "none",
							duration: 1000
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/apiMember/orderdetail/main?id=" + this.$root.$mp.query.orderId
							});
						}, 1000);
					} else {
						uni.showToast({
							title: "订单支付成功",
							icon: "none",
							duration: 1000
						});
						setTimeout(() => {
							uni.redirectTo({
								url: "/apiMember/orderdetail/main?id=" + this.$root.$mp.query.orderId
							});
						}, 1000);
					}
				}
			},

			async getPayment() {
				let paymentData = await getPaymentListApi({});
				if (paymentData.data.info.length === 0) {
					uni.showToast({
						title: "请配置支付方式",
						icon: "none",
						duration: 2000
					});
				} else {
					this.pay_id = paymentData.data.info[0].pay_code;
				}

				paymentData.data.info.forEach(obj => {
					if (obj.pay_code === "balance") {
						this.balance = true;
						this.balance_amount = obj.amount_txt;
					}
					if (obj.pay_code === "alipay") {
						this.alipay = true;
					}
					if (obj.pay_code === "wxpay") {
						this.wxpay = true;
					}
				});
			},
			//总的点击按钮
			async startPay() {
				// console.log("类型"+this.paytype);
				switch (this.paytype) {
					//预存款支付
					case "deposit":
						this.depositPay();
						return false;
						break;

						//小程序微信支付
					case "wxpaywxapp":
						this.wxpaywxappPay();
						return false;
						break;
						//小程序支付宝支付
					case "malipaymyapp":
						this.malipaymyappPay();
						return false;
						break;
						//微信H5支付
					case "wxpayh5":
						this.wxpayh5Pay();
						return false;
						break;
						//支付宝H5支付
					case "malipaynew":
						this.malipaynewPay();
						return false;
						break;
						//微信app支付
					case "wxpayappplus":
						this.wxpayappplusPay();
						return false;
						break;
						//支付宝app支付
					case "malipayappplus":
						this.malipayappplusPay();
						return false;
						//线下支付
					case "bankcard":
						this.bankcardPay();
						return false;
						break;
					case "credit":
						this.creditCardPay();
						return false;
						break;
					case "jcbpremo":
						this.jcbPremoPay();
						return false;
						break;
					default:
						return false;
						break;
				}
			},
			async tokenResult(response, _this) {
				if (response.resultCode != '000') {
					// show error message
					uni.showToast({
						title: '※ 正確なクレジットカード情報を入力してくだい。',
						duration: 2000,
						icon: "none"
					});
					
				} else {
					let token = response.tokenObject.token;
					let params = {
						pay_type: _this.paytype,
						order_id: _this.orderId,
						pay_token: token,
						money: _this.actualPrice
					}
					const payParams = await doPaymentCreditApi(params);
					if (payParams.data.dopay === false) {

						console.info(payParams.data.info);
						// 支付失败
						uni.redirectTo({
							url: "/apiCart/payresult/main?status=0&orderId=" +
								this.orderId +
								"&money=" +
								this.actualPrice +
								"&paytype=" +
								this.paytype
						});
						return false;
					}
					uni.redirectTo({
						url: "/apiCart/payresult/main?status=1&orderId=" +
							this.orderId +
							"&money=" +
							this.actualPrice +
							"&paytype=" +
							this.paytype
					});
				}
			},
			//信用卡支付
			async creditCardPay() {

				let card_no_empty = '※ 没有输入卡号。';
				let card_no_length = '※ 卡号请输入7位以上。';
				let card_name1_empty = '※ 卡片名义人名：未输入姓名。';
				let card_name1_alphanumeric = '※ 卡片名义人名：名字请以半角英数输入。';
				let card_name2_empty = '※ 卡名义人名：未输入姓氏。';
				let card_name2_alphanumeric = '※ 卡名义人名：姓请以半角英数输入。';
				let security_code_empty = '※ 未输入安全代码。';
				let security_code_number = '※ 请用数值输入安全代码。';
				let security_code_length = '※ 请输入4位数以下的安全码。';


				let cardNo = this.cardNo.replace(/\s+/g, "");
				
				//验证信用卡
				if (cardNo == "") {
					uni.showToast({
						title: card_no_empty,
						duration: 2000,
						icon: "none"
					});
					this.security_code = "";
					//$('#shopping_order_card_no').focus();
					return false;
				}

				// カード番号の7桁未満チェック
				if (cardNo.length < 7) {
					uni.showToast({
						title: card_no_length,
						duration: 2000,
						icon: "none"
					});
					this.security_code = "";
					return false;
				}

				var date = new Date();
				var year = date.getFullYear();
				year = String(year);
				year = year.substring(0, 2);
				var expire = year + this.expire_year + this.expire_month;

				var card_name1 = this.card_name1;
				if (card_name1 == "") {
					uni.showToast({
						title: card_name1_empty,
						duration: 2000,
						icon: "none"
					});
					this.security_code = "";
					return false;
				}
				// 名義人名：名の文字種チェック
				var pat = /^[0-9a-zA-Z]*$/;
				if (!pat.test(card_name1)) {
					uni.showToast({
						title: card_name1_alphanumeric,
						duration: 2000,
						icon: "none"
					});
					this.security_code = "";
					return false;
				}

				var card_name2 = this.card_name2;
				if (card_name2 == "") {
					uni.showToast({
						title: card_name1_empty,
						duration: 2000,
						icon: "none"
					});
					this.security_code = "";
					return false;
				}
				// 名義人名：姓の文字種チェック
				var pat = /^[0-9a-zA-Z]*$/;
				if (!pat.test(card_name2)) {
					uni.showToast({
						title: card_name2_alphanumeric,
						duration: 2000,
						icon: "none"
					});
					this.security_code = "";
					return false;
				}

				let holdername = card_name1.concat(' ').concat(card_name2);
				if (this.security_code.length == 0 || this.security_code == "") {
					uni.showToast({
						title: security_code_empty,
						duration: 2000,
						icon: "none"
					});
					return false;
				}

				// セキュリティコードの数値のみチェック
				var pat = /^\d*$/;
				if (!pat.test(this.security_code)) {
					uni.showToast({
						title: security_code_number,
						duration: 2000,
						icon: "none"
					});
					this.security_code = "";
					return false;
				}

				// セキュリティコードの4桁以下チェック
				if (this.security_code.length > 4) {
					uni.showToast({
						title: security_code_length,
						duration: 2000,
						icon: "none"
					});
					this.security_code = "";
					return false;
				}

				let data = {
					holdername: holdername,
					cardno: cardNo, // card number without spaces
					expire: expire, // expiry in format 'YYYYMM'
					securitycode: this.security_code
				};

				let _this = this;
				//信用卡输入项的验证
				//Multipayment.init('tshop00046703');
				Multipayment.init('9200002869198');
				Multipayment.getToken(data, function(response) {
					_this.tokenResult(response, _this);
				});
				return false;
			},
			
			async jcbPremoPay(){
				
				let card_no_empty = '※ 没有输入卡号。';
				let card_no_length = '※ 卡号请输入7位以上。';
				let card_password_empty = '※ 没有输入认证番号。';
				
				let cardNo = this.jcbCardNo.replace(/\s+/g, "");
				
				if (cardNo == "") {
					uni.showToast({
						title: card_no_empty,
						duration: 2000,
						icon: "none"
					});
					return false;
				}
				
				// カード番号の7桁未満チェック
				if (cardNo.length < 7) {
					uni.showToast({
						title: card_no_length,
						duration: 2000,
						icon: "none"
					});
					return false;
				}
				
				//カード認証番号
				if (this.jcbPassword == "") {
					uni.showToast({
						title: card_password_empty,
						duration: 2000,
						icon: "none"
					});
					return false;
				}
				
				
				let params = {
					pay_type: this.paytype,
					order_id: this.orderId,
					card_no: cardNo,
					card_pwd : this.jcbPassword,
					money: this.actualPrice
				}
				
				let status = 1;
				const payParams = await doPaymentJcbPreMoApi(params);
				if (payParams.data.dopay === false) {
					status = 0;
				}
				uni.redirectTo({
					url: "/apiCart/payresult/main?status="+ status +"&orderId=" +
						this.orderId +
						"&money=" +
						this.actualPrice +
						"&paytype=" +
						this.paytype
				});
			},
			//预存款支付
			async depositPay() {
				if (Number(this.advance) < Number(this.actualPrice)) {
					uni.showToast({
						icon: "none",
						title: "余额不足"
					});
					return false;
				}
				const payParams = await doPaymentBalanceApi({
					pay_id: this.paytype,
					order_id: this.orderId,
					money: this.actualPrice
				});
				if (payParams.data.dopay === false) {
					// 支付失败

					uni.redirectTo({
						url: "/apiCart/payresult/main?status=0&orderId=" +
							this.orderId +
							"&money=" +
							this.actualPrice +
							"&paytype=" +
							this.paytype
					});
					return false;
				}
				uni.redirectTo({
					url: "/apiCart/payresult/main?status=1&orderId=" +
						this.orderId +
						"&money=" +
						this.actualPrice +
						"&paytype=" +
						this.paytype
				});
			},
			// 微信小程序支付
			async wxpaywxappPay() {
				const payParams = await payDopaymentApi({
					pay_type: "wxpayMp",
					order_id: this.orderId,
					money: this.actualPrice,
					openid: uni.getStorageSync("openId")
				});
				if (payParams.data.res === false) {
					uni.showToast({
						icon: "none",
						title: payParams.data.msg
					});
					return false;
				}
				this.payParams = payParams;
				let _this = this;
				uni.requestPayment({
					provider: "wxpay",
					timeStamp: payParams.data.timeStamp,
					nonceStr: payParams.data.nonceStr,
					package: payParams.data.package,
					signType: "MD5",
					paySign: payParams.data.paySign,
					success: function(res) {
						uni.redirectTo({
							url: "/apiCart/payresult/main?status=1&orderId=" +
								_this.orderId +
								"&money=" +
								_this.actualPrice
						});
					},
					fail: function(res) {
						console.log(_this.orderId);
						uni.redirectTo({
							url: "/apiCart/payresult/main?status=0&orderId=" +
								_this.orderId +
								"&money=" +
								_this.actualPrice
						});
					}
				});
			},
			// 支付宝小程序支付
			async malipaymyappPay() {
				const payParams = await payDopaymentApi({
					paytype: this.paytype,
					orderId: this.orderId,
					money: this.actualPrice
				});
				console.log(payParams);
				this.payParams = payParams;
				let _this = this;
				if (this.payParams.trade_no) {
					uni.tradePay({
						tradeNO: this.payParams.trade_no,
						success: function(res) {
							// uni.alert(res.resultCode);
							console.log(res);
							uni.redirectTo({
								url: "/apiCart/payresult/main?status=1&orderId=" +
									_this.orderId +
									"&money=" +
									_this.actualPrice +
									"&paytype=" +
									this.paytype
							});
						},
						fail: function(res) {
							uni.redirectTo({
								url: "/apiCart/payresult/main?status=0&orderId=" +
									_this.orderId +
									"&money=" +
									_this.actualPrice +
									"&paytype=" +
									this.paytype
							});
							// uni.alert(res.resultCode);
							console.log(res);
						}
					});
				}
			},
			// 微信H5支付
			async wxpayh5Pay() {
				if (this.iswechatH5) {
					const wechatPay = await wechatPayApi({
						order_id: this.orderId,
						code: this.code,
						money: this.actualPrice
					});

					if (wechatPay.data.status == 'code') {
						window.location = wechatPay.data.url;
						return false;
					}
					if (wechatPay.data.res === true) {
						// var pay_info = wechatPay.data.result;
						var params = {
							//公众号名称，由商户传入
							appId: wechatPay.data.result.appId, // merchant id
							//时间戳，自1970年以来的秒数
							timeStamp: wechatPay.data.result.timeStamp, // prepay id
							//随机字符串
							nonceStr: wechatPay.data.result.nonceStr, // nonce

							package: wechatPay.data.result.package, // timestamp
							//微信签名方式：
							signType: "MD5", // signed string
							//Sign=WXPay
							paySign: wechatPay.data.result.paySign
						};
						this.onBridgeReady(params, wechatPay.data.redirect_url);
					} else {
						// 失败
						uni.showToast({
							title: wechatPay.data.msg,
							icon: "none",
							duration: 1500
						});
						return false;
					}
					return false;

				}
				const payParams = await payDopaymentApi({
					pay_id: this.paytype,
					order_id: this.orderId,
					money: this.actualPrice,
					pay_type: "wxpayH5"
				});
				if (payParams.data.res === false) {
					// 失败
					uni.showToast({
						title: payParams.data.msg,
						icon: "none",
						duration: 1500
					});
					return false;
				}
				if (payParams.data.res === true) {
					// 跳往微信

					location.href = payParams.data.url;
				}
			},
			// 支付宝H5支付
			async malipaynewPay() {
				console.log(window.location.href);
				let pay_url =
					this.alipaywap +
					"&order_sn=" +
					this.orderId +
					"&body=" +
					this.goods_name +
					"&money=" +
					this.actualPrice +
					"&quit_url=" +
					window.location.href;
				console.log(pay_url);
				location.href = pay_url;
			},
			// 微信app支付
			async wxpayappplusPay() {
				console.log("微信APP支付");
				const payParams = await payDopaymentApi({
					order_id: this.orderId,
					money: this.actualPrice,
					pay_type: "wxpayApp"
				});
				uni.requestPayment({
					provider: "wxpay",
					orderInfo: payParams.data.response,
					success: function(res) {
						console.log("支付成功");
						console.log(res);
					},
					fail: function(res) {
						console.log("失败");
						console.log(res);
					}
				});
			},
			async bankcardPay() {
				let _this = this;
				const payParams = await payDopaymentApi({
					order_id: this.orderId,
					money: this.actualPrice,
					pay_type: "bankcard"
				});

				uni.redirectTo({
					url: "/apiCart/payresult/main?status=1&orderId=" + _this.orderId + "&money=" + _this.actualPrice + "&paytype=" +
						this.paytype
				});
			},
			async onBridgeReady(target, redirect_url) {
				WeixinJSBridge.invoke("getBrandWCPayRequest", target, function(res) {
					// alert(JSON.stringify(target)); 
					// alert(JSON.stringify(res)); 
					if (res.err_msg == "get_brand_wcpay_request:ok") {
						// 使用以上方式判断前端返回,微信团队郑重提示： 
						//res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。 
						location.href = redirect_url;
					}
				});
			},
			// 支付宝app支付
			async malipayappplusPay() {
				console.log("支付宝支付");
				const payParams = await payDopaymentApi({
					order_id: this.orderId,
					money: this.actualPrice,
					pay_type: "alipayApp"
				});
				let _this = this;
				uni.requestPayment({
					provider: "alipay",
					orderInfo: payParams.data.response.payInfo,
					success: function(res) {
						console.log(res);
						console.log("成功支付");
						console.log(_this.orderId);
						console.log("-------");
						uni.redirectTo({
							url: "/apiCart/payresult/main?status=1&orderId=" + _this.orderId
						});
					},
					fail: function(res) {
						console.log(res);
						console.log("支付失败");
					}
				});
			},
			async getWechatOpenid() {
				//微信登录开始
				uni.showLoading({
					title: "登录中...", //提示的内容,
					mask: true, //显示透明蒙层，防止触摸穿透,
					success: res => {}
				});

				// 微信登录开始
				uni.login({
					success: async res => {
						if (res.code) {
							this.code = res.code;
							console.log("code：" + this.code);
							const data = await loginWechatApi({
								code: this.code,
								platform: "MP-WEIXIN-MOBILE"
							});
							if (data.data.res === true) {
								// 获取成功 记录openid
								uni.setStorageSync("openId", data.data.openid); // 将openid记录
							}
							uni.setStorageSync("openId", data.data.openid); // 将openid记录
						}
					}
				});
			},
			async getPaymentIsUse() {
				const data = await getPaymentIsUseApi({});
				this.small_is_use = data.data.small_is_use;
				this.hfive_is_use = data.data.hfive_is_use;
				this.app_is_use = data.data.app_is_use;
				this.zhifu_is_use = data.data.zhifu_is_use;
			}
		}
	};
</script>
<style lang='scss' scoped>
	@import "./style";
</style>
